package pearson.automation.forms;

import org.openqa.selenium.By;

import framework.BaseForm;
import framework.elements.Button;
import framework.elements.Label;

public class AssetDetailsForm extends BaseForm {

    private static Label formIdentifier = new Label(
            By.className("details"), "Details form");

    private Label title = new Label(
            By.xpath("//h1[@data-item-title]"), "Title");
    private Label thumbnail = new Label(
            By.xpath("//div[@id='detailed-results']"
                   + "//div[@class='item-image']//img"), "Thumbnail");
    private Button newCourse = new Button(
            By.className("cta-new"), "New button");
    private Button addTo = new Button(
            By.className("cta-add"), "Add To button");
    private Button addToLibrary = new Button(
            By.className("cta-library"), "Add To Library button");
    private Button preview = new Button(
            By.className("preview-cta"), "Preview button");
    private Button flowPlayer = new Button(
            By.tagName("iframe"), "Flowplayer");

    public AssetDetailsForm() {
        super(formIdentifier.getLocator(), "Details form");
    }

    public final String getTitle() {
        return title.getText();
    }

    public final String getThumbnailURL() {
        return thumbnail.getElement().getAttribute("src");
    }

    public final boolean hasPreviewButton() {
        return preview.isPresent();
    }

    public final boolean hasNewButton() {
        return newCourse.isPresent();
    }

    public boolean hasAddToButton() {
        return addTo.isPresent();
    }

    public final boolean hasAddToLibraryButton() {
        return addToLibrary.isPresent();
    }

    public final boolean hasFlowPlayer() {
        return flowPlayer.isPresent();
    }

    public final void clickNew() {
        newCourse.clickAndWait();
    }

    public final LightBoxForm clickPreview() {
        preview.clickAndWait();
        return new LightBoxForm();
    }

    public final LightBoxForm clickThumbnail() {
        thumbnail.clickAndWait();
        return new LightBoxForm();
    }

}
